<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: SyndicatePortlet.php 416 2011-01-04 21:30:56Z steen.rabol $
 * @package Pradoportal.Porttlets.SimpleTextPortlet.Edit
 *
 */

Prado::using('Application.Portlets.Portlet');
//Prado::using('Application.Portlets.SyndicatePortlet.Common.SyndicatePortletRecord');
Prado::using('Application.Common.Data.PortalConfigRecord');

class SyndicatePortlet extends Portlet
{
	protected function getConfigName()
	{
		return get_class() . '_' . $this->Parameters['id'];
	}

	public function dataBind()
	{
		if($this->ConfigRecord && isset($this->ConfigRecord->value))
		{
			$v = Prado::unserialize($this->ConfigRecord->value);
			$this->tbSyndicateUrl->Text = $v['syndicateurl'];

			if(isset($v['width']))
			{
				$this->tbWidth->Text	= $v['width'];
			}

			if(isset($v['height']))
			{
				$this->tbHeight->Text	= $v['height'];
			}

			if(isset($v['border']))
			{
				$this->cbBorder->Checked	= TPropertyValue::ensureBoolean($v['border']);
			}

			if(isset($v['scrolling']))
			{
				if(TPropertyValue::ensureInteger($v['scrolling']) == 1)
					$this->cbScrolling->Checked	= true;
			}

		}
	}

	public function onLoad($p)
	{
		parent::onLoad($p);
		if(!$this->Page->IsPostBack)
		{
			$this->dataBind();
		}
	}

	public function SaveContent($sender,$param)
	{
		if(!$this->ConfigRecord)
		{
			$this->ConfigRecord	= new PortalConfigRecord();
			$this->ConfigRecord->name	= "syndicateportlet_" . $this->Parameters['id'];
		}

		$this->ConfigRecord->value	= Prado::serialize(
														array(
															'syndicateurl' => $this->tbSyndicateUrl->Text,
															'width' => $this->tbWidth->Text,
															'height' => $this->tbHeight->Text,
															'border' => $this->cbBorder->checked,
															'scrolling' => $this->cbScrolling->Checked
															)
														);
		$this->ConfigRecord->save();
	}

	public function CancelContent($sender,$param)
	{
		$this->dataBind();
	}

	public function DeleteButtonClicked($sender,$param)
	{
		// Delete any portlet specific content from db
		if($this->ConfigRecord)
		{
			if($this->ConfigRecord !== null)
			{
				if($this->ConfigRecord instanceof PortalActiveRecord)
				{
					$this->ConfigRecord->delete();
				}
			}
		}

		parent::DeleteButtonClicked($sender,$param);
	}
}
?>